package com.adminsystem.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.adminsystem.entity.BusWebsite;
import com.adminsystem.service.IBusWebsiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 网址收录Controller
 *
 * @author admin
 * @date 2023-11-19
 */
@RestController
@RequestMapping("/bus/website")
public class BusWebsiteController extends BaseController
{
    @Autowired
    private IBusWebsiteService busWebsiteService;

    /**
     * 查询网址收录列表
     */
    @PreAuthorize("hasAuthority('bus:website:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusWebsite busWebsite)
    {
        startPage();
        List<BusWebsite> list = busWebsiteService.selectBusWebsiteList(busWebsite);
        return getDataTable(list);
    }

    /**
     * 导出网址收录列表
     */
    @PreAuthorize("hasAuthority('bus:website:export')")
    @Log(title = "网址收录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusWebsite busWebsite)
    {
        List<BusWebsite> list = busWebsiteService.selectBusWebsiteList(busWebsite);
        ExcelUtil<BusWebsite> util = new ExcelUtil<BusWebsite>(BusWebsite.class);
        util.exportExcel(response, list, "网址收录数据");
    }

    /**
     * 获取网址收录详细信息
     */
    @PreAuthorize("hasAuthority('bus:website:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busWebsiteService.selectBusWebsiteById(id));
    }

    /**
     * 新增网址收录
     */
    @PreAuthorize("hasAuthority('bus:website:add')")
    @Log(title = "网址收录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusWebsite busWebsite)
    {
        return toAjax(busWebsiteService.insertBusWebsite(busWebsite));
    }

    /**
     * 修改网址收录
     */
    @PreAuthorize("hasAuthority('bus:website:edit')")
    @Log(title = "网址收录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusWebsite busWebsite)
    {
        return toAjax(busWebsiteService.updateBusWebsite(busWebsite));
    }

    /**
     * 删除网址收录
     */
    @PreAuthorize("hasAuthority('bus:website:remove')")
    @Log(title = "网址收录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busWebsiteService.deleteBusWebsiteByIds(ids));
    }
}
